// 添加商品页面所用到的请求
import { number } from "echarts";
import instacne from "../request";
import type { Ref } from "vue";
/**
 * 查询所有一级分类及子分类
 */
export interface withChildrenData {
  children?: withChildrenData[];
  description: string;
  icon: string;
  id: number;
  keywords: string;
  level: number;
  name: string;
  navStatus: number;
  parentId: number;
  productCount: number;
  productUnit: string;
  showStatus: number;
  sort: number;
}
export const withChildren = (): Promise<withChildrenData[]> =>
  instacne.get("/productCategory/list/withChildren");
/**
 * 获取全部品牌列表
 *
 */
export interface IlistAllBrand {
  bigPic: string;
  brandStory: string;
  factoryStatus: number;
  firstLetter: string;
  id: number;
  logo: string;
  name: string;
  productCommentCount: number;
  productCount: number;
  showStatus: number;
  sort: number;
}
export const listAllBrand = (): Promise<IlistAllBrand[]> =>
  instacne.get("/brand/listAll");

/**
 * 取所有商品属性分类及其下属性
 *
 */
export interface IallProductAttribute {
  attributeCount: number;
  id: number;
  name: string;
  paramCount: number;
  productAttributeList: [
    {
      filterType: number;
      handAddStatus: number;
      id: number;
      inputList: string;
      inputType: number;
      name: string;
      productAttributeCategoryId: number;
      relatedStatus: number;
      searchType: number;
      selectType: number;
      sort: number;
      type: number;
    }
  ];
}
export const allProductAttribute = (): Promise<IallProductAttribute[]> =>
  instacne.get("/productAttribute/category/list/withAttr");

/**
 *
 * 根据分类查询属性列表或参数列表
 * type为0时 查询属性列表
 * type为1时 查询参数列表
 */
interface IattrListParams {
  cid: number;
  type: number;
  pageSize?: number;
  pageNum?: number;
}
export interface IattrListRes {
  list: [
    {
      filterType: number;
      handAddStatus: number;
      id: number;
      inputList: string;
      inputType: number;
      name: string;
      productAttributeCategoryId: number;
      relatedStatus: number;
      searchType: number;
      selectType: number;
      sort: number;
      type: number;
    }
  ];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}
export const attrList = (data: IattrListParams): Promise<IattrListRes> =>
  instacne.get(`/productAttribute/list/${data.cid}`, {
    params: {
      pageNum: data?.pageNum ? data.pageNum : 1,
      pageSize: data?.pageSize ? data.pageSize : 5,
      type: data.type,
    },
  });

/**
 * /subject/listAll
 * 所有专题
 */
export const subListAll = (): Promise<any> => instacne.get(`/subject/listAll`);
/**
 * /prefrenceArea/listAll
 * 关联优选
 */
export const prefListAll = (): Promise<any> =>
  instacne.get(`/prefrenceArea/listAll`);

/**
 * 创建商品
 * /product/create
 */
export const createProduct = (data: any) =>
  instacne.post(`/product/create`, data);

/**
 * 分页查询商品列表
 * /product/list
 *
 */
export const proList = (data?: any): Promise<any> =>
  instacne.get(`/product/list`, {
    params: data,
  });

/**
 * 查询商品
 * /product/list
 */
export const serachProList = (data?: any): Promise<any> =>
  instacne.get(`/product/list`, {
    params: data,
  });

/**
 * 人气推荐
 * /recommendProduct/list
 */
export const recommendProduct = (data?: any): Promise<any> =>
  instacne.get(`/home/recommendProduct/list`, {
    params: data,
  });

/**
 * 删除商品
 * /home/recommendProduct/delete
 */
export const delPro = (ids: number) =>
  instacne.post(`/home/recommendProduct/delete`, `ids=${ids}`);

/**
 * 分页选择商品
 * /product/list
 */
export const proPageList = (data?: any): Promise<any> =>
  instacne.get(`/product/list`, {
    params: data,
  });

/**
 * 删除商品列表中的数据
 * /product/update/deleteStatus
 */
export const deleteStatus = (data: { ids: number; deleteStatus: number }) =>
  instacne.post(`/product/update/deleteStatus`, null, {
    params: {
      ids: data.ids,
      deleteStatus: data.deleteStatus,
    },
  });

/**
 * 更新出版状态
 * /product/update/publishStatus
 */
export const updatePublishStatus = (data: {
  ids: number;
  publishStatus: number;
}) =>
  instacne.post(`/product/update/publishStatus`, null, {
    params: {
      ids: data.ids,
      publishStatus: data.publishStatus,
    },
  });

/**
 *
 * 更新新品状态
 * /product/update/newStatus
 */
export const updateNewStatus = (data: { ids: string; newStatus: number }) =>
  instacne.post(`/product/update/newStatus`, null, {
    params: {
      ids: data.ids,
      newStatus: data.newStatus,
    },
  });

/**
 * /product/update/recommendStatus
 * 更新推荐状态
 */
export const updateRecommendStatus = (data: {
  ids: string;
  recommendStatus: number;
}) =>
  instacne.post(`/product/update/recommendStatus`, null, {
    params: {
      ids: data.ids,
      recommendStatus: data.recommendStatus,
    },
  });

/**
 * /product/update/deleteStatus
 * 批量删除状态数据
 */
export const deleteStatusBatch = (data: {
  ids: string;
  deleteStatus: number;
}) =>
  instacne.post(`/product/update/deleteStatus`, null, {
    params: {
      ids: data.ids,
      deleteStatus: data.deleteStatus,
    },
  });

/**删除人气推荐
 * /home/recommendProduct/delete
 */
export const deleteHotRecommend = (data: { ids: string }) =>
  instacne.post(`/home/recommendProduct/delete`, null, {
    params: {
      ids: data.ids,
    },
  });

/**
 * 人气推荐修改
 * /home/recommendProduct/update/recommendStatus
 */
export const hotRecommendStatus = (data: {
  ids: number;
  recommendStatus: number;
}) =>
  instacne.post(`/home/recommendProduct/update/recommendStatus`, null, {
    params: {
      ids: data.ids,
      recommendStatus: data.recommendStatus,
    },
  });
